#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
long long n, des;
const long long mod = 99997867;
vector<long long> pos_v;
long long find(int start, int end, long long pos) {
    long long l = start, r = end;
    while (l < r) {
        long long mid = (l + r + 1) >> 1;
        if (pos_v[mid] <= pos + des)
            l = mid;
        else
            r = mid - 1;
    }
    return r;
}
inline long long j(long long m) {
    long long res = 1;
    for (int i = m; i > 0; i--) {
        res *= i;
    }
    return res;
}
long long Cn2(long long m) {
    //化简
    // long long ab = j(m);
    // long long bl = j(m - 2) * 2;
    return m * (m - 1) / 2;
}
int main() {
    cin >> n >> des;
    for (long long i = 0; i < n; i++) {
        long long pos;
        cin >> pos;
        pos_v.push_back(pos);
    }
    long long res = 0;
    for (long long i = 0; i < n; i++) {
        if (pos_v.size() - i < 3)
            break;
        //long long max_pos = find(i + 1, pos_v.size() - 1, pos_v[i]);
        long long max_pos = upper_bound(pos_v.begin(), pos_v.end(),
                                        pos_v[i] + des) - pos_v.begin() - 1;
        int len = max_pos - i;
        res += Cn2(max_pos - i);
        res %= 99997867;
    }
    cout << res;
    //find
    //C2n
    return 0;
}